﻿using System;
using System.Collections;
using System.Data;
using CE.Database;
using CE.Security;

/// <summary>
/// Summary description for ContactUsDB
/// </summary>
namespace CE.ContactUs
{
    public class ContactUsDB
    {
        public ContactUsDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public Int64 Insert(ContactUs contactus)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocContactUsInsertUpdateSingleItem";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CUID", contactus.CUId);
            _sPara.Add("@Salutation", contactus.Salutation);
            _sPara.Add("@Name", contactus.Name);
            _sPara.Add("@Designation", contactus.Designation);
            _sPara.Add("@CompanyName", contactus.CompanyName);
            _sPara.Add("@Tel", contactus.Tel);
            _sPara.Add("@Email", contactus.Email);
            _sPara.Add("@TypeofService", contactus.TypeofService);
            _sPara.Add("@PreferredCountry", contactus.PreferredCountry);
            _sPara.Add("@Industry", contactus.Industry);
            _sPara.Add("@Comments", contactus.Comments);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public ContactUs GetContactUsDetails(Int64 CUID)
        {
            MyDatabase _Db = new MyDatabase();
            string _spName = "sprocContactUsSelectSingleItem";
            ContactUs _result = null;
            DataTable _dt;
            SortedList _sPara = new SortedList();

            _sPara.Add("@CUID", CUID);

            _dt = _Db.GetDataTableBySP(_spName, _sPara);

            if (_dt != null && _dt.Rows.Count > 0)
            {
                _result = new ContactUs();
                _result = FillDataRecord(_dt);
            }

            return _result;
        }
        public bool Update()
        {
            return true;
        }

        public bool Delete()
        {
            return true;
        }

        private ContactUs FillDataRecord(DataTable myDataTable)
        {
            ContactUs myContactUs = new ContactUs();
            myContactUs.CUId = Convert.ToInt64(myDataTable.Rows[0]["CUId"].ToString());
            myContactUs.Salutation = myDataTable.Rows[0]["Salutation"].ToString();
            myContactUs.Name = myDataTable.Rows[0]["Name"].ToString();
            myContactUs.Designation = myDataTable.Rows[0]["Designation"].ToString();
            myContactUs.CompanyName = myDataTable.Rows[0]["CompanyName"].ToString();
            myContactUs.Tel = myDataTable.Rows[0]["Tel"].ToString();
            myContactUs.Email = myDataTable.Rows[0]["Email"].ToString();
            myContactUs.TypeofService = myDataTable.Rows[0]["TypeofService"].ToString();
            myContactUs.PreferredCountry = myDataTable.Rows[0]["PreferredCountry"].ToString();
            myContactUs.Industry = myDataTable.Rows[0]["Industry"].ToString();
            myContactUs.Comments = myDataTable.Rows[0]["Comments"].ToString();
            myContactUs.CreatedDate = Convert.ToDateTime(myDataTable.Rows[0]["CreatedDate"].ToString());
            myContactUs.ModifiedDate = Convert.ToDateTime(myDataTable.Rows[0]["ModifiedDate"].ToString());

            return myContactUs;
        }
    }
}